﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ECONTACT.Bussiness;
using ECONTACT.DataLayer;
using System.Data;
using System.Windows.Forms;
using DevComponents.DotNetBar.Controls;
using DevComponents.Editors.DateTimeAdv;

namespace ECONTACT.Controller
{
    public class TaiKhoanCtrl
    {
        TaiKhoanData m_TaiKhoanData = new TaiKhoanData();
        TaiKhoanInfo m_TaiKhoanInfo = new TaiKhoanInfo();

        #region Hien thi ComboBox
        public void HienThiComboBox(ComboBoxEx comboBox)
        {
            comboBox.DataSource = m_TaiKhoanData.LayDsTaiKhoan();
            comboBox.DisplayMember = "MaTK";
            comboBox.ValueMember = "MaTK";
        }
        #endregion

        #region Do du lieu vao DataGridView
        public void HienThi(DataGridViewX dGV, ComboBoxEx MaTK)
        {
            BindingSource bS = new BindingSource();

            bS.DataSource = m_TaiKhoanData.LayTTTaiKhoan(MaTK.Text);
            
            dGV.DataSource = bS;
        }
        #endregion

        #region Dang nhap
        public int DangNhap(string m_Username, string m_Password)
        {
            DataTable m_DT = m_TaiKhoanData.LayDsTaiKhoan(m_Username);

            if (m_DT.Rows.Count == 0)
                return 0;

            String m_SysPass = m_DT.Rows[0]["MatKhau"].ToString();

            if (m_SysPass != m_Password)
                return 1;
            else
            {
                m_TaiKhoanInfo.HoTen = m_DT.Rows[0]["HoTen"].ToString(); // lay de hiện tên cho màu mè tý
                m_TaiKhoanInfo.MaLoaiTK = m_DT.Rows[0]["MaLoaiTK"].ToString(); // lay de phan quyen

                //m_TaiKhoanInfo.MaLoaiTK = m_LoaiNguoiDungInfo;

                Utilities.NguoiDung = m_TaiKhoanInfo;
                return 2; // danh nhap thanh cong
            }
        }
        #endregion
    }
}
